home *** CD-ROM | disk | FTP | other *** search
/ Aminet 24 / Aminet 24 (1998)(GTI - Schatztruhe)[!][Apr 1998].iso / Aminet / dev / c / cxref_1_4a.lha / html.c < prev    next >
C/C++ Source or Header  |  1997-12-07  |  33KB  |  1,195 lines

  1. /***************************************
  2.   $Header: /home/amb/cxref/RCS/html.c 1.22 1997/11/20 19:19:06 amb Exp $
  3.  
  4.   C Cross Referencing & Documentation tool. Version 1.4a.
  5.  
  6.   Writes the HTML output.
  7.   ******************/ /******************
  8.   Written by Andrew M. Bishop
  9.  
  10.   This file Copyright 1995,96,97 Andrew M. Bishop
  11.   It may be distributed under the GNU Public License, version 2, or
  12.   any higher version.  See section COPYING of the GNU Public license
  13.   for conditions under which this file may be redistributed.
  14.   ***************************************/
  15.  
  16. #include <stdlib.h>
  17. #include <stdio.h>
  18. #include <string.h>
  19. #include <sys/types.h>
  20. #include <sys/stat.h>
  21. #include <unistd.h>
  22.  
  23. #ifdef AMIGA
  24. #include "amiga.h"
  25. #endif /* AMIGA */
  26.  
  27. #include "memory.h"
  28. #include "datatype.h"
  29. #include "cxref.h"
  30.  
  31. /*+ The name of the output tex file that includes each of the others. +*/
  32. #define HTML_FILE        ".html"
  33. #define HTML_FILE_BACKUP ".html~"
  34.  
  35. /*+ The name of the output tex file that contains the appendix. +*/
  36. #define HTML_APDX        ".apdx"
  37.  
  38. /*+ The comments are to be inserted verbatim. +*/
  39. extern int option_verbatim_comments;
  40.  
  41. /*+ The name of the directory for the output. +*/
  42. extern char* option_odir;
  43.  
  44. /*+ The base name of the file for the output. +*/
  45. extern char* option_name;
  46.  
  47. /*+ The directories to go back to get to the base output directory. +*/
  48. static char* goback=NULL;
  49.  
  50. static void WriteHTMLFilePart(File file);
  51. static void WriteHTMLInclude(Include inc);
  52. static void WriteHTMLSubInclude(Include inc,int depth);
  53. static void WriteHTMLDefine(Define def);
  54. static void WriteHTMLTypedef(Typedef type);
  55. static void WriteHTMLStructUnion(StructUnion su,int depth);
  56. static void WriteHTMLVariable(Variable var);
  57. static void WriteHTMLFunction(Function func);
  58.  
  59. static void WriteHTMLDocument(char* name,int appendix);
  60. static void WriteHTMLPreamble(FILE* f,char* title,int sourcefile);
  61. static void WriteHTMLPostamble(FILE* f,int sourcefile);
  62.  
  63. static char* html(char* c);
  64.  
  65. /*+ The output file for the HTML. +*/
  66. static FILE* of;
  67.  
  68. /*++++++++++++++++++++++++++++++++++++++
  69.   Write an html file for a complete File structure and all components.
  70.  
  71.   File file The File structure to output.
  72.   ++++++++++++++++++++++++++++++++++++++*/
  73.  
  74. void WriteHTMLFile(File file)
  75. {
  76.  char* ofile;
  77.  int i;
  78.  
  79.  /* Write the including file. */
  80.  
  81.  WriteHTMLDocument(file->name,0);
  82.  
  83.  /* Open the file */
  84.  
  85.  ofile=ConcatStrings(4,option_odir,"/",file->name,HTML_FILE);
  86.  
  87.  of=fopen(ofile,"w");
  88.  if(!of)
  89.    {
  90.     struct stat stat_buf;
  91.     int i,ofl=strlen(ofile);
  92.  
  93.     for(i=strlen(option_odir)+1;i<ofl;i++)
  94.        if(ofile[i]=='/')
  95.          {
  96.           ofile[i]=0;
  97.           if(stat(ofile,&stat_buf))
  98.              mkdir(ofile,S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH);
  99.           ofile[i]='/';
  100.          }
  101.  
  102.     of=fopen(ofile,"w");
  103.    }
  104.  
  105.  if(!of)
  106.    {fprintf(stderr,"cxref: Failed to open the HTML output file '%s'\n",ofile);exit(1);}
  107.  
  108.  for(goback="",i=strlen(file->name);i>0;i--)
  109.     if(file->name[i]=='/')
  110.        goback=ConcatStrings(2,goback,"../");
  111.  
  112.  /* Write out a header. */
  113.  
  114.  WriteHTMLPreamble(of,ConcatStrings(5,"Cross reference for ",file->name," of ",option_name,"."),0);
  115.  
  116.  /*+ The file structure is broken into its components and they are each written out. +*/
  117.  
  118.  WriteHTMLFilePart(file);
  119.  
  120.  if(file->includes)
  121.    {
  122.     Include inc =file->includes;
  123.     fprintf(of,"\n<hr>\n<h2>Included Files</h2>\n\n");
  124.     do{
  125.        WriteHTMLInclude(inc);
  126.       }
  127.     while((inc=inc->next));
  128.    }
  129.  
  130.  if(file->defines)
  131.    {
  132.     Define def =file->defines;
  133.     fprintf(of,"\n<hr>\n<h2>Preprocessor definitions</h2>\n\n");
  134.     do{
  135.        if(def!=file->defines)
  136.           fprintf(of,"<p>\n");
  137.        WriteHTMLDefine(def);
  138.       }
  139.     while((def=def->next));
  140.    }
  141.  
  142.  if(file->typedefs)
  143.    {
  144.     Typedef type=file->typedefs;
  145.     do{
  146.        WriteHTMLTypedef(type);
  147.       }
  148.     while((type=type->next));
  149.    }
  150.  
  151.  if(file->variables)
  152.    {
  153.     int any_to_mention=0;
  154.     Variable var=file->variables;
  155.  
  156.     do{
  157.        if(var->scope&(GLOBAL|LOCAL|EXTERNAL|EXTERN_F))
  158.           any_to_mention=1;
  159.       }
  160.     while((var=var->next));
  161.  
  162.     if(any_to_mention)
  163.       {
  164.        int first_ext=1,first_local=1;
  165.        Variable var=file->variables;
  166.        do{
  167.           if(var->scope&GLOBAL)
  168.              WriteHTMLVariable(var);
  169.          }
  170.        while((var=var->next));
  171.        var=file->variables;
  172.        do{
  173.           if(var->scope&(EXTERNAL|EXTERN_F) && !(var->scope&GLOBAL))
  174.             {
  175.              if(first_ext)
  176.                {fprintf(of,"\n<hr>\n<h2>External Variables</h2>\n\n"); first_ext=0;}
  177.              else
  178.                 fprintf(of,"<p>\n");
  179.              WriteHTMLVariable(var);
  180.             }
  181.          }
  182.        while((var=var->next));
  183.        var=file->variables;
  184.        do{
  185.           if(var->scope&LOCAL)
  186.             {
  187.              if(first_local)
  188.                {fprintf(of,"\n<hr>\n<h2>Local Variables</h2>\n\n"); first_local=0;}
  189.              else
  190.                 fprintf(of,"<p>\n");
  191.              WriteHTMLVariable(var);
  192.             }
  193.          }
  194.        while((var=var->next));
  195.       }
  196.    }
  197.  
  198.  if(file->functions)
  199.    {
  200.     Function func=file->functions;
  201.     do{
  202.        if(func->scope&(GLOBAL|EXTERNAL))
  203.           WriteHTMLFunction(func);
  204.       }
  205.     while((func=func->next));
  206.     func=file->functions;
  207.     do{
  208.        if(func->scope&LOCAL)
  209.           WriteHTMLFunction(func);
  210.       }
  211.     while((func=func->next));
  212.    }
  213.  
  214.  WriteHTMLPostamble(of,0);
  215.  
  216.  fclose(of);
  217.  
  218. /* Clear the memory in html() */
  219.  
  220.  html(NULL); html(NULL); html(NULL); html(NULL);
  221. }
  222.  
  223.  
  224. /*++++++++++++++++++++++++++++++++++++++
  225.   Write a File structure out.
  226.  
  227.   File file The File to output.
  228.   ++++++++++++++++++++++++++++++++++++++*/
  229.  
  230. static void WriteHTMLFilePart(File file)
  231. {
  232.  int i;
  233.  
  234.  fprintf(of,"<h1><a name=\"file\">File %s</a></h1>\n",html(file->name));
  235.  
  236.  if(file->comment)
  237.     if(option_verbatim_comments)
  238.        fprintf(of,"<pre>\n%s\n</pre>\n\n",html(file->comment));
  239.     else
  240.       {
  241.        char *rcs1=strstr(file->comment,"$Header"),*rcs2=NULL;
  242.        if(rcs1)
  243.          {
  244.           rcs2=strstr(&rcs1[1],"$");
  245.           if(rcs2)
  246.             {
  247.              rcs2[0]=0;
  248.              fprintf(of,"<b>RCS %s</b>\n<p>\n",html(&rcs1[1]));
  249.              rcs2[0]='$';
  250.             }
  251.          }
  252.        if(rcs2)
  253.           fprintf(of,"%s\n<p>\n",html(&rcs2[2]));
  254.        else
  255.           fprintf(of,"%s\n<p>\n",html(file->comment));
  256.       }
  257.  
  258.  if(file->inc_in->n)
  259.    {
  260.     int i;
  261.  
  262.     fprintf(of,"<dl compact>\n<dt>Included in:\n<dd><ul>\n");
  263.     for(i=0;i<file->inc_in->n;i++)
  264.        fprintf(of,"<li><a href=\"%s%s"HTML_FILE"#file\">%s</a><br>\n",goback,file->inc_in->s[i],html(file->inc_in->s[i]));
  265.     fprintf(of,"</ul></dl>\n");
  266.    }
  267.  
  268.  if(file->f_refs->n || file->v_refs->n)
  269.     fprintf(of,"<dl compact>\n");
  270.  
  271.  if(file->f_refs->n)
  272.    {
  273.     int others=0;
  274.     fprintf(of,"<dt>References Functions:\n<dd><ul>\n");
  275.     for(i=0;i<file->f_refs->n;i++)
  276.        if(file->f_refs->s2[i])
  277.           fprintf(of,"<li><a href=\"%s%s"HTML_FILE"#func-%s\">%s()  :  %s</a>\n",goback,file->f_refs->s2[i],file->f_refs->s1[i],html(file->f_refs->s1[i]),html(file->f_refs->s2[i]));
  278.        else
  279.           others++;
  280.  
  281.     if(others)
  282.       {
  283.        fprintf(of,"<li>");
  284.        for(i=0;i<file->f_refs->n;i++)
  285.           if(!file->f_refs->s2[i])
  286.              fprintf(of,--others?" %s(),":" %s()",html(file->f_refs->s1[i]));
  287.        fprintf(of,"\n");
  288.       }
  289.     fprintf(of,"</ul>\n");
  290.    }
  291.  
  292.  if(file->v_refs->n)
  293.    {
  294.     int others=0;
  295.     fprintf(of,"<dt>References Variables:\n<dd><ul>\n");
  296.     for(i=0;i<file->v_refs->n;i++)
  297.       {
  298.        if(file->v_refs->s2[i])
  299.           fprintf(of,"<li><a href=\"%s%s"HTML_FILE"#var-%s\">%s  :  %s</a>\n",goback,file->v_refs->s2[i],file->v_refs->s1[i],html(file->v_refs->s1[i]),html(file->v_refs->s2[i]));
  300.        else
  301.           others++;
  302.       }
  303.  
  304.     if(others)
  305.       {
  306.        fprintf(of,"<li>");
  307.        for(i=0;i<file->v_refs->n;i++)
  308.           if(!file->v_refs->s2[i])
  309.              fprintf(of,--others?" %s,":" %s",html(file->v_refs->s1[i]));
  310.        fprintf(of,"\n");
  311.       }
  312.     fprintf(of,"</ul>\n");
  313.    }
  314.  
  315.  if(file->f_refs->n || file->v_refs->n)
  316.     fprintf(of,"</dl>\n");
  317. }
  318.  
  319.  
  320. /*++++++++++++++++++++++++++++++++++++++
  321.   Write an Include structure out.
  322.  
  323.   Inclu